/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SPPPanel.java
 *
 * Created on Jun 3, 2010, 5:19:58 PM
 */

package gui.panels;

/**
 *
 * @author andreazagnoli
 */
public class SPPPanel extends javax.swing.JPanel {

	private static final long serialVersionUID = -8198240290802719560L;

	/** Creates new form SPPPanel */
    public SPPPanel() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        spp_p1 = new javax.swing.JTextField();
        spp_p0 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        spp_k = new javax.swing.JTextField();

        setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Additional Parameters", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.ABOVE_TOP));

        jLabel1.setText("P0");

        jLabel2.setText("P1");

        jLabel3.setText("k");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(9, 9, 9)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(spp_p0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(spp_p1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(spp_k, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(44, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(spp_p0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(spp_p1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 16, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(spp_k, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField spp_k;
    private javax.swing.JTextField spp_p0;
    private javax.swing.JTextField spp_p1;
    // End of variables declaration//GEN-END:variables

    public boolean checkParameters() {
    	if (spp_p0.getText().equals("") || spp_p1.getText().equals("") || spp_k.getText().equals(""))
    		return false;
    	try {
    		double p0 = Double.parseDouble(spp_p0.getText());
    		double p1 = Double.parseDouble(spp_p1.getText());
    		double k = Double.parseDouble(spp_k.getText());
    		if (p0 + p1 != 1)
    			return false;
    		if (k <= 0)
    			return false;
    		return true;
    	}
    	catch (NumberFormatException e) { }
    	return false;
    }
    
    public double getP0() {
    	try {
    		return Double.parseDouble(spp_p0.getText());
    	}
    	catch (NumberFormatException e) { }
    	return -1;
    }
    
    public double getP1() {
    	try {
    		return Double.parseDouble(spp_p1.getText());
    	}
    	catch (NumberFormatException e) { }
    	return -1;
    }
    
    public int getK() {
    	try {
    		return Integer.parseInt(spp_k.getText());
    	}
    	catch (NumberFormatException e) { }
    	return -1;
    }
}
